#ifndef LABELMODEL_H
#define LABELMODEL_H

#include <QAbstractListModel>
#include <QtQml>
#include <QApplication>
#include <QDebug>
#include "BaseResult.h"
#include <QString>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>

class LabelModelData {
public:
    LabelModelData(const int &seq, const QString &labelName,const QString &labelColor = "black");

    QString labelName() const;
    QString labelColor() const;
    int seq() const;

    bool operator==(const LabelModelData&  labelModelData) const;
    QJsonObject toJsonObject();

private:
    int _seq_;
    QString _labelName_;
    QString _labelColor_;
};


class LabelModel : public QAbstractListModel {
Q_OBJECT

public :
    enum DataRoles{
        LabelNameRole = 1,
        LabelColorRole = 2,
        SeqRole
    };
    explicit LabelModel(QObject *parent = 0);
    ~LabelModel();

public :
    virtual int rowCount(const QModelIndex &parent) const;
    virtual QVariant data(const QModelIndex &index, int role) const;


    Q_INVOKABLE BaseResult::JsonResult get(const int &index);
    Q_INVOKABLE BaseResult::JsonResult remove(const QString &labelName);
    Q_INVOKABLE BaseResult::JsonResult append(const QString &labelName,const QString &labelColor);
    int count() const;
    Q_INVOKABLE void setSavePath(const QString &savePath);
    static LabelModelData getFromSeq(int seq);




protected :
    virtual QHash<int, QByteArray> roleNames() const;


private :
    static QList<LabelModelData> _dataList_;
    static int seq;
    Q_INVOKABLE void insert(int index,const LabelModelData &data);
    Q_INVOKABLE void remove(int index);
    QString _savePath_;
    int saveDataList2Local();
    bool isExisted(const LabelModelData& labelModeData);
};


#endif // LABELMODEL_H
